<?php

namespace app\configure\controller;

use app\configure\model\ConfigSystemModel;
use think\admin\Controller;
use think\db\exception\DataNotFoundException;
use think\db\exception\DbException;
use think\db\exception\ModelNotFoundException;

class System extends Controller
{
    /**
     * 当前操作数据库
     * @var string
     */
    private string $table = 'System';

    /**
     * API配置管理
     * @auth true
     * @menu true
     * @throws DataNotFoundException
     * @throws DbException
     * @throws ModelNotFoundException
     */
    public function index()
    {
        $this->title = 'APP配置管理';

        $query = $this->_query(ConfigSystemModel::class);
        // 加载对应数据
        $this->type = $this->request->get('type', 'wechat');
        if ($this->type === 'wepay') $query->where(['type' => 'wepay']);
        elseif ($this->type === 'sms') $query->where(['type' => 'sms']);
        elseif ($this->type === 'wechat') $query->where(['type' => 'wechat']);
        elseif ($this->type === 'property_fee') $query->where(['type' => 'property_fee']);

        $query->equal('type')
            ->like('name')
            ->page(true, true);
    }

    /**
     * 修改
     * @auth true
     * @throws ModelNotFoundException
     * @throws DataNotFoundException
     * @throws DbException
     */
    public function edit()
    {
        $this->_applyFormToken();
        $this->_form(ConfigSystemModel::class, 'form');
    }

    public function _form_filter()
    {

    }
}